import { createPopupSlot } from '@/services/popupSlot'
import { IFormValues, IMsgDetail } from './interface'

export const popupSlot = createPopupSlot()

export const textInputFields = ['title']

/** 根据详情创建初始的表单数据 */
export const createInitialFormValues = (data: IMsgDetail | null): IFormValues => {
  // 默认值尽可能使用空串
  const values: IFormValues = {
    channelType: '1',
    templateId: '',
    enableFlag: 1,
    eventType: 1,
    receiveObj: 1,
    routeIds: [],
    sendType: 1,
    title: '',
    type: 1,
    messageRouteList: [],
    templateList: [],
  }
  if (data) {
    const vals = values as any
    const dat = data as any
    Object.keys(vals).forEach(key => {
      if (dat[key] != null) {
        vals[key] = dat[key] // 赋值
      }
    })
  }
  return values
}
